package com.qcby.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.qcby.dao.HallMapper;
import com.qcby.model.Hall;
import com.qcby.model.dto.HallVo;
import com.qcby.query.HallQuery;
import com.qcby.service.HallService;
import com.qcby.util.Page;

@Service
public class HallServiceImpl extends BaseServiceImpl<HallQuery, Hall> implements
      HallService {


   private HallMapper hallDao;

   @Autowired
   public void setBrandDao(HallMapper hallDao) {
      this.hallDao = hallDao;
      this.baseDao = hallDao;
   }

   @Override
   public List<Hall> selectAllByCid(Integer cId) {
      return hallDao.selectAllByCid(cId);
   }

   @Override
   public void deleteByCid(Integer cId) {
      hallDao.deleteByCid(cId);
   }

   @Override
   public Page<HallVo> query(String hName, Integer cId, Integer pageNo, Integer pageSize) {
      Integer startNum = (pageNo - 1) * pageSize;
      Page<HallVo> page = new Page<>();
      page.setPageNo(pageNo);
      page.setPageSize(pageSize);
      page.setStartNum(startNum);
      List<HallVo> list = hallDao.query(hName, cId, startNum, pageSize);
      Integer count = hallDao.queryCount(hName, cId);

      page.setTotalCount(count);
      page.setList(list);
      page.setTotalPage(count % pageSize == 0 ? count / pageSize : (count / pageSize) + 1);
      return page;
   }
}
